package arraylistexer;

import java.util.ArrayList;

/**
 * @author tongchen
 * @create 2022-09-27 19:00
 */
public class Poker {
    public String suit;
    int num;

    public Poker(String suit, int num) {
        this.suit = suit;
        this.num = num;
    }

    @Override
    public String toString() {
        return "Poker{" +
                "suit='" + suit + '\'' +
                ", num=" + num +
                '}';
    }

    public String getSuit() {
        return suit;
    }

    public void setSuit(String suit) {
        this.suit = suit;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
}
class CardDemo{
    private final String[]arr={"♠", "♥", "♣", "♦"};
    //创建ArrayList用来存牌
    ArrayList<Poker>list=new ArrayList<>(52);
    public ArrayList<Poker> buyPoker(){
        for (int i=0;i<arr.length;++i){
            for (int j = 1; j <=13; j++) {
                Poker poker = new Poker(arr[i], j);
                list.add(poker);
            }
        }
        return list;
    }
    //洗牌
    public void shuffle(ArrayList<Poker>list){
        for (int i=0;i<list.size();++i){
            int ranom=(int)(Math.random()*52);
            Poker poker=list.get(i);
            list.set(i,list.get(ranom));
            list.set(ranom,poker);
        }

    }
    //发牌
    public void deal(ArrayList<Poker>pokers){
        //创建三个poker的顺序表，代表三个人
        ArrayList<ArrayList<Poker>>men=new ArrayList<>();
        for (int i=0;i<3;++i){
            men.add(new ArrayList<Poker>());
        }
        //双层循环进行发牌
        for (int i = 0; i <5 ; i++) {
            for (int j=0;j<men.size();++j){
                men.get(j).add(pokers.remove(0));
            }
        }
        System.out.println("玩家一手中的牌："+men.get(0));
        System.out.println("玩家二手中的牌："+men.get(1));
        System.out.println("玩家三手中的牌："+men.get(2));
        System.out.println("剩余的牌"+pokers);
    }

}
